﻿using System.Collections.Generic;
using System.Linq;
using Dexter.DataTransferObject;
using Dexter.Domain.Results;

namespace Dexter.Domain.Model
{
	public static class PageHelper
	{
		public static IEnumerable<PageDto> ToDtos(this IEnumerable<Page> s)
		{
			return s.Select(x => x.ToDto()).ToList();
		}

		public static PageDto ToDto(this Page s)
		{
			var r = new PageDto();

			r.Abstract = s.Abstract;
			r.BreakOnAggregate = s.BreakOnAggregate;
			r.CommentEnabled = s.CommentEnabled;
			r.FormattedBody = s.FormattedBody;
			r.Id = s.Id;
			r.PublishDate = s.PublishDate;
			r.ShowOnAggregate = s.ShowOnAggregate;
			r.ShowOnSearch = s.ShowOnSearch;
			r.Slug = s.Slug;
			r.Tags = s.Tags.Select(x => x.Name).ToArray();
			r.Title = s.Title;
			r.TotalComments = s.TotalComments;
			r.TotalTrackback = s.TotalTrackback;
			r.Username = s.Username;

			r.TrackBacks = s.TrackBacks.ToDtos();
			r.Comments = s.Comments.ToDtos();
			
			return r;
		}

		//public static IEnumerable<PostLightDto> ToLightDtos(this IEnumerable<Item> s)
		//{
		//    return s.Select(x => x.ToDtoLight()).ToList();
		//}

		//public static PostLightDto ToDtoLight(this Item s)
		//{
		//    var r = new PostLightDto();

		//    r.Id = s.Id;
		//    r.Slug = s.Slug;
		//    r.Title = s.Title;

		//    return r;
		//}

		public static IPagedResult<PageDto> ToDtos(this IPagedResult<Page> s)
		{
			return new PagedResult<PageDto>(s.PageIndex, s.PageSize, s.Result.ToDtos(), s.TotalCount);
		}
	}
}